package com.c6906.vdam.dps.schedule;

import com.c6906.vdam.dps.config.DpsOpenStatus;
import com.c6906.vdam.dps.service.TerminalBusinessInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Author : TAOHUIQI
 * @Date: 2024/7/24 21:22
 * @Description:
 */
@Component
@EnableConfigurationProperties({DpsOpenStatus.class})
public class LastGpsSync {

    private static final Logger logger = LoggerFactory.getLogger(LastGpsSync.class);

    @Resource
    TerminalBusinessInfoService terminalBusinessInfoService;
    @Resource
    DpsOpenStatus openStatus;

    /**
     * 每30秒更新最新轨迹表VehiclesLastGps
     */
    @Scheduled(cron = "0/30 * * * * ?")
    public void updateTerminalGPSToDMScheduled() {
        if (openStatus.getOpenStatus() && openStatus.getOpenLastGpsToRedis()) {
            logger.info("开始执行更新lastgps定时任务");
            boolean flag = terminalBusinessInfoService.updateBatchTerminalDataToDM();
            if (flag) {
                logger.info("定时更新达梦数据库轨迹表成功!");
            } else {
                logger.info("定时更新达梦数据库轨迹表失败!");
            }
        }
    }
}
